<?php
session_start();
require_once ("database.php");
$conn=mysql_link();

if ($_GET["action"]=="jilu"){
    $sousuo=$_POST['sousuo'];

}
$sql5 = "select * from borrowrecords  ";
$query = mysqli_query($conn, $sql5);
//where RecordID like '%$sousuo%' or BookID link '%$sousuo%'

//分页功能
$num = mysqli_num_rows($query);
$pageSize = 5;
$totalPage = ceil($num / $pageSize);
if ($_GET['page']) {
    $page = $_GET['page'];
} else {
    $page = 1;
}
if ($page == 1) {
    $up = 1;
} else {
    $up = $page - 1;
}
if ($page == $totalPage) {
    $next = $totalPage;
} else {
    $next = $page + 1;
}
$start = ($page - 1) * $pageSize;
$sql5 = "select * from borrowrecords  where RecordID like '%$sousuo%' or BookID like '%$sousuo%' limit $start, $pageSize ";
$res5 = mysqli_query($conn, $sql5);
$result = mysqli_fetch_all($res5, MYSQLI_ASSOC);

?>
<!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/BorrowingRecord.css">
    <link href="https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css" rel="stylesheet" />
 </head>
 <body>
  <div class="all">
    <!-- 左手边菜单栏 -->
    <div class="h left_Menu_Bar Center">
        <div class="Menu_Bar Center">
            <!-- 头像 -->
            <div class="avatar">
                <!-- 默认头像 -->
                <h1 class="avatar_tou">管</h1>
            </div>
            <!-- 菜单 -->
            <div class="Menu Font">
                <ul class="Center ct">
                    <li><a href="#">用户管理</a></li>
                    <li><a href="#">图书管理</a></li>
                    <li>
                        <a href="#">借阅管理</a> <button class="btn" id="btn"><i class="bx bx-chevron-down"
                                id="arrow"></i></button>
                    </li>
                </ul>
            </div>
        </div>
               <!-- 下拉菜单 -->
               <div class="box " id="dropdown">
                <ul class="drop_down_menu Center">
                  <li><a href="./BorrowBooks.html">借阅</a></li>
                  <li><a href="BookReturn.php">归还</a> </li>
                  <li><a href="BorrowingRecord.php">记录</a> </li>
                    <!-- <li><a href="#">过期</a></li> -->
                </ul>
            </div>
            <div  class="client"><button class="client_btn"></button>客户端</div>
    </div>

    <div class="borrow-record">
      <h1 class="title">借阅记录</h1>
        <p class="list">借阅记录</p>
        <form action="?action=jilu" method="post">
        <div class="button">
            <div class="search">
              <input type="text" name="sousuo" placeholder="请输入编号/书名">
              <button>
                <img src="../img/搜索.png" alt="">
              </button>
            </div>
<!--            <div style="display: flex;">-->
<!--              <div class="new"><img src="../img/新增.png" alt=""><a href="">新增</a></div>-->
<!--              <div class="delete"><img src="../img/删除.png" alt=""><a href="">删除</a></div>-->
<!--            </div>-->
        </div>
        <div class="Information">
            <ul class="blue">
              <li>编号</li>
              <li>书籍</li>
              <li>图书编号</li>
              <li>作者</li>
              <li>借阅时间</li>
              <li>归还时间</li>
            </ul>
            <?foreach ($result as $value){?>
            <ul class="white">
              <li><?echo $value['RecordID']?></li>
              <li><?echo $value['Bookname']?></li>
              <li><?echo $value['BookID']?></li>
              <li><?echo $value['paper']?></li>
              <li><?echo $value['BorrowDate']?></li>
              <li><?echo $value['ReturnDate']?></li>
              <li class="more">更多</li>
             </ul>
<?}?>
        </div>
        </form>
        <div class="page-turning">
            <a href="BorrowingRecord.php?page=<?php echo $up; ?>"><button>上一页</button></a>
            <a href="BorrowingRecord.php?page=<?php echo $next; ?>"><button>下一页</button></a>
      </div>


    </div>
  </div>
  <script src="../js/BorrowingRecord.js"></script>
 </body>
 </html>